package com.ruoyi.operation.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.operation.domain.bo.TFileListBo;
import com.ruoyi.operation.domain.vo.TFileListVo;
import com.ruoyi.operation.service.ITFileListService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件列控制器
 * 前端访问路由地址为:/operation/fileList
 *
 * @author ruoyi
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fileList")
public class TFileListController extends BaseController {

    private final ITFileListService iTFileListService;

    /**
     * 查询文件列列表
     */
    @SaCheckPermission("operation:fileGroup:list")
    @GetMapping("/list")
    public TableDataInfo<TFileListVo> list(TFileListBo bo, PageQuery pageQuery) {
        return iTFileListService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文件列列表
     */
    @SaCheckPermission("operation:fileGroup:export")
    @Log(title = "文件列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TFileListBo bo, HttpServletResponse response) {
        List<TFileListVo> list = iTFileListService.queryList(bo);
        ExcelUtil.exportExcel(list, "文件列", TFileListVo.class, response);
    }

    /**
     * 获取文件列详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("operation:fileGroup:query")
    @GetMapping("/{id}")
    public R<TFileListVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iTFileListService.queryById(id));
    }

    /**
     * 新增文件列
     */
    @SaCheckPermission("operation:fileGroup:add")
    @Log(title = "文件列", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TFileListBo bo) {
        return toAjax(iTFileListService.insertByBo(bo));
    }

    /**
     * 修改文件列
     */
    @SaCheckPermission("operation:fileGroup:edit")
    @Log(title = "文件列", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TFileListBo bo) {
        return toAjax(iTFileListService.updateByBo(bo));
    }

    /**
     * 删除文件列
     *
     * @param ids 主键串
     */
    @SaCheckPermission("operation:fileGroup:remove")
    @Log(title = "文件列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iTFileListService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
